<template>
  <div class="job-container">
    <el-form class="job-form" :model="job" ref="jobRef" label-width="120px" :rules="jobRules" label-position="top">
      <el-form-item label="id" v-if="false" prop="id">
        <el-input v-model="job.id" name="id" />
      </el-form-item>
      <el-form-item label="编码" prop="code">
        <el-input v-model="job.code" name="code" />
      </el-form-item>
      <el-form-item label="岗位名称" prop="name">
        <el-input v-model="job.name" name="name" />
      </el-form-item>
      <el-form-item label="岗位描述" prop="described">
        <el-input type="textarea" v-model="job.described" name="described" />
      </el-form-item>
      <el-form-item label="最大年龄" prop="maxAge">
        <el-input type="number"  v-model.number="job.maxAge" name="maxAge"/>
      </el-form-item>
      <el-form-item label="岗位类别" prop="jobType">
        <el-input v-model="job.jobType" name="jobType"/>
      </el-form-item>
      <el-form-item label="科室" prop="department">
        <el-input v-model="job.department" name="department"/>
      </el-form-item>
      <el-form-item label="人员类别" prop="personType">
        <el-input v-model="job.personType"  name="personType"/>
      </el-form-item>
      <el-form-item label="最低学历" prop="lowBachelor">
        <el-input v-model="job.lowBachelor"  name="lowBachelor"/>
      </el-form-item>
      <el-form-item label="最低学位" prop="lowDegree">
        <el-input v-model="job.lowDegree"  name="lowDegree"/>
      </el-form-item>
      <el-form-item label="其他条件" prop="otherCondition">
        <el-input type="textarea" v-model="job.otherCondition"  name="otherCondition"/>
      </el-form-item>
      <el-form-item label="发布日期" required>
        <el-col :span="12">
          <el-form-item prop="publishDate">
            <el-date-picker
              v-model="job.publishDate"
              type="date"
              placeholder=""
              style="width: 100%"
            />
          </el-form-item>
        </el-col>
      </el-form-item>
      <el-form-item label="截止日期">
        <el-col :span="12">
          <el-form-item prop="endDate">
            <el-date-picker
              v-model="job.endDate"
              type="date"
              placeholder=""
              style="width: 100%"
            />
          </el-form-item>
        </el-col>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">保存</el-button>
        <el-button @click="onCancel">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useI18n } from 'vue-i18n'
import { ElMessage } from 'element-plus'
import { add, modify } from '@/api/common/common'
const job = ref({})

const id = ref(null)

const jobRef = ref(job.value)

const i18n = useI18n()
const jobRules = ref({
  code: [
    {
      required: true,
      trigger: 'blur',
      message: '岗位编码不能为空'
    }
  ],
  name: [
    {
      required: true,
      trigger: 'blur',
      message: '岗位名称不能为空'
    }
  ],
  described: [
    {
      required: true,
      trigger: 'blur',
      message: '岗位描述不能为空'
    }
  ],
  maxAge: [
    {
      required: true,
      trigger: 'blur',
      message: '年龄限制不能为空'
    }
  ],
  jobType: [
    {
      required: true,
      trigger: 'blur',
      message: '岗位类型不能为空'
    }
  ],
  department: [
    {
      required: true,
      trigger: 'blur',
      message: '科室不能为空'
    }
  ],
  personType: [
    {
      required: true,
      trigger: 'blur',
      message: '人员类别不能为空'
    }
  ]
})
const onSubmit = () => {
  if (id.value) { // 判断id是否为空
    job.value.id = id.value
    modify(job, id.value, 'job').then(res => {
      // 关闭该页面
      ElMessage.success('更新成功')
    })
  } else {
    add(job, 'job').then(res => {
      ElMessage.success('新增成功')
    })
  }
}

const onCancel = () => {
  console.log(1)
}
</script>

<style lang="scss" scoped>
.job-container {
  min-height: 100%;
  width: 100%;
  .job-form {
    position: relative;
    width: 90%;
    max-width: 100%;
    top: 50px;
    left: 40px;
  }
}
</style>
